﻿import QtQuick 2.11
//import QtQuick.Controls 1.4
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2

import ".."
import "../_Global"

import "../_Global/Global.js" as GlobalJS
import "../GameJS.js" as GameJS

Item {
    signal s_reg()  //立即注册
    signal s_forgot()  //立即注册
    signal s_login(var param)   //立即登录
    signal s_minimized()    //最小化

    function serverResponseMsg(msg) {
        _private.showMsg(msg);
        enableLogin();
    }

    function enableLogin() {
        loginForm.buttonLogin.enabled = true;
    }

    /*
    function showMsgBox(msg) {
       msgBox.text = msg
       msgBox.visible = true;
    }
    */

    id: loginWindow
    visible: true
    //width: 674
    //height: 394
    //flags: { (flags | Qt.FramelessWindowHint)}
    //color: "#ff0000"
    //color: Qt.transparent
    //title: qsTr("英语杀登录")
    anchors.fill: parent


    Image { //背景图
        source: Global._FixResourcePath_R("Media/Images/Class/Back.png")
        //fillMode: Image.Tile
        anchors.fill: parent
    }

    LoginForm {
        id: loginForm
        anchors.centerIn: parent
        //anchors.fill: parent
        width: Global.gamePos.mapLogin.rectBack.width
        height: Global.gamePos.mapLogin.rectBack.height
        mouseMinimized.onClicked: s_minimized()
        mouseReg.onClicked: s_reg()
        mouseForgot.onClicked: s_forgot()
        onS_login: {
            if(textUser.text.length < 4) {
                _private.showMsg("用户名或密码错误");
                //msgBox.text = "用户名太短"
                //msgBox.visible = true;
                return ;
            }
            if(textPass.text.length < 6) {
                _private.showMsg("用户名或密码错误");
                return ;
            }

            var paramObj = new Object;
            paramObj.userName = textUser.text
            paramObj.password = textPass.text
            //_private.showMsg(paramObj.password)
            //msgBox.text = paramObj.password
            //msgBox.visible = true;
            //showMsgBox(paramObj.password)
            _private.showMsg("正在登录...");
            buttonLogin.enabled = false;
            loginWindow.s_login(paramObj);
        }

    }

    Label {
        x: Global.dpW(50)
        y: Global.dpH(1030)
        width: Global.dpW(300)
        height: Global.dpH(30)
        text: qsTr("交流QQ群：206170128")
        color: "white"
        font.pixelSize: Global.dpH(20)
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
    }

    MessageDialog {
        id: msgBox
        text: ""
        title: "深林孤鹰警告你"
        visible: false
    }


    QtObject {  //私有数据,函数,对象等
        id: _private
        function showMsg(msg) {
            loginForm.labelMsg.text = msg;
        }
    }
}
